package com.blockmeta.bbs.immodule.bean.databean;

import com.blockmeta.bbs.baselibrary.base.app.BaseApp;
import com.blockmeta.bbs.baselibrary.utils.FormatUtil;
import com.blockmeta.bbs.baselibrary.utils.SharedPreferenceUtil;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.immodule.bean.beaninterface.IMarketAndF10Bean;
import com.google.gson.annotations.SerializedName;

import java.text.DecimalFormat;

public class MarketContentBean implements IMarketAndF10Bean {
    private final static DecimalFormat sDecimalFormat = new DecimalFormat("0.0000");
    private final static DecimalFormat sDecimalFormat2 = new DecimalFormat("0.00");
    private final static DecimalFormat sDecimalFormat3 = new DecimalFormat("0.000");
    /**
     * k线
     *{"change":"-0.53%","coin":"btc","currency":"usd","exchange":"huobipro","img":"https://appserversrc.8btc.com/coin_info/img/20200422095102_47800.png","price":"9232.94"}
     */
    public String change;
    public String coin ;
    public String currency;
    public String exchange;
    public String logo;
    public String img;
    public String price;
    @SerializedName("last_convert")
    public double priceRMB;
    @SerializedName("pair_base_info")
    public PairBaseInfo pairBaseInfo;

    public Ticker ticker;

    private boolean isChecked;

    private double rate = SharedPreferenceUtil.getFloat(BaseApp.getApp(), Constant.CNY_USD, 6.4f);

    public static class PairBaseInfo{
        @SerializedName("symbol_show")
        public String symbolShow;
        @SerializedName("currency_show")
        public String currencyShow;
    }

    public static class Ticker{
        public String change;

        public double volume;
    }

    @Override
    public String getSimpleName() {
        return (pairBaseInfo.symbolShow+"/"+pairBaseInfo.currencyShow).toUpperCase();
    }

    @Override
    public String getPriceRMB() {
        return "¥ "+sDecimalFormat.format(priceRMB);
    }

    @Override
    public String getMarketValue() {
        return "成交量 "+sDecimalFormat3.format(ticker.volume);
    }

    @Override
    public String getPriceDollar() {
        price = FormatUtil.cny2usd(priceRMB,rate);
        return "$ "+price;
    }

    @Override
    public double getIncrease() {
        double increase = Double.parseDouble(ticker.change);
        if (increase>0){
            change = String.format("+%s%%", sDecimalFormat2.format(increase));
        }else {
            change = String.format("%s%%", sDecimalFormat2.format(increase));
        }
        return Double.parseDouble(ticker.change);
    }

    @Override
    public String getFullName() {
        return exchange;
    }

    @Override
    public void setSelected(boolean selected) {
        img = logo;
        isChecked = selected;
    }

    @Override
    public boolean isSelected() {
        return isChecked;
    }
}
